package com.kitty.game.fight.pet;

import com.kitty.game.fight.bean.Fight;
import com.kitty.game.fight.bean.FightObject;
import com.kitty.common.utils.SpringUtils;
import com.kitty.game.fight.service.FightMessageService;
import com.kitty.game.fight.util.FightMessageUtil;
import com.kitty.game.fight.util.FightRateUtil;

/**
 * 舍命一击
 * 被法术击中目标的MP相应下降，而施法者的HP值降为1
 */
public class SheMingYiJiProcessor extends PetSkillProcessor {

    @Override
    public void trigger(Fight fight, FightObject effector, FightObject target, int skillLevel, Object... args) {
        if (effector.isFallDown()) {
            return;
        }
        if (!FightRateUtil.isPetSkillHit(effector, target)) {
            return;
        }
        int selfHp = effector.getCurrLife();
        // 舍命一击技能等级*0.01 换算百分比% 扣除被施法当前目标最大蓝量百分比%
        int costMp = (int)(skillLevel * 0.01 * target.getMaxMana());
        // 被法术击中目标的MP相应下降
        target.reduceMp(costMp);
        FightMessageService fightMessageService = SpringUtils.getFightMessageService();
        /*头顶掉蓝动画*/
        FightMessageUtil.sendFightPackage(fight, fightMessageService.decreaseMana(effector.getId(), target.getId(), costMp, 0));
        FightMessageUtil.sendFightPackage(fight, fightMessageService.updateObjectInfo(target));

        // 施法者的HP值降为1
        effector.setCurrLife(1);
        FightMessageUtil.sendFightPackage(fight, fightMessageService.decreaseLife(effector.getId(), effector.getId(), -(selfHp-1), 0, 0));
        FightMessageUtil.sendFightPackage(fight, fightMessageService.updateTargetLife(effector.getId(), effector.getCurrLife()));

    }

    @Override
    public Boolean effect(Fight fight, FightObject effector, FightObject target, Object... args) {
        return Boolean.TRUE;
    }

}
